package com.ankicoo.practice.other;

import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.annotation.JsonAlias;

import java.math.BigInteger;
import java.util.*;

public class TableDateParse {
    public static class TableData {
        /** 表名->对应标签名称*/
        private String tableName;
        /** 表对应书签id*/
        private BigInteger bookmarkId;
        /** 是否书写表头*/
        private Boolean writeHeader;
        /**表头*/
        private List<TableHeader> header;
        /**数据列表*/
        private List<Map<String,Object>> dataList;

        public Boolean getWriteHeader() {
            return writeHeader;
        }

        public void setWriteHeader(Boolean writeHeader) {
            this.writeHeader = writeHeader;
        }

        public String getTableName() {
            return tableName;
        }

        public void setTableName(String tableName) {
            this.tableName = tableName;
        }

        public BigInteger getBookmarkId() {
            return bookmarkId;
        }

        public void setBookmarkId(BigInteger bookmarkId) {
            this.bookmarkId = bookmarkId;
        }

        public List<TableHeader> getHeader() {
            return header;
        }

        public void setHeader(List<TableHeader> header) {
            this.header = header;
        }

        public List<Map<String, Object>> getDataList() {
            return dataList;
        }

        public void setDataList(List<Map<String, Object>> dataList) {
            this.dataList = dataList;
        }

    }
    public static class TableHeader {
        private String key;
        private String name;

        public TableHeader() {
        }

        public TableHeader(String key) {
            this.key = key;
        }

        public TableHeader(String key, String name) {
            this.key = key;
            this.name = name;
        }

        public String getKey() {
            return key;
        }

        public void setKey(String key) {
            this.key = key;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

    }



    public static void main(String[] args) {
        TableData tableData = new TableData();
        tableData.setTableName("自定义租金计划表");
        tableData.setWriteHeader(Boolean.TRUE);
        List<TableHeader> headers = new ArrayList<>();
        headers.add(new TableHeader("period", "期次"));
        headers.add(new TableHeader("amount", "金额"));
        headers.add(new TableHeader("date", "应收日期"));
        tableData.setHeader(headers);

        List<Map<String, Object>> dataList = new ArrayList<>();
        Map<String,Object> rowMap = null;
        for (int i = 0; i < 6; i++) {
            rowMap = new HashMap<>();
            rowMap.put("period", i + 1);
            rowMap.put("amount", 2000 * (i + 1));
            rowMap.put("date", DateUtil.now());
            dataList.add(rowMap);
        }
        tableData.setDataList(dataList);

        System.out.println(JSONUtil.toJsonStr(tableData));
    }

}
